package com.hczt.fire.framework.jpa.configuration.dataSource;


//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
//import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
//import org.springframework.orm.jpa.JpaTransactionManager;
//import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
//import org.springframework.transaction.PlatformTransactionManager;
//
//import javax.repository.EntityManagerFactory;
//import javax.sql.DataSource;

/**
 * @author marvin.ma
 * @create 2017-09-28 9:20
 * 先注入LocalContainerEntityManagerFactoryBean
 * 再获取EntityManagerFactory
 *
 * EntityManagerFactory类似于Hibernate的SessionFactory,mybatis的SqlSessionFactory
 * 总之,在执行操作之前,我们总要获取一个EntityManager,
 * 这就类似于Hibernate的Session, mybatis的sqlSession.
 * 注入EntityManagerFactory有两种方式,一种是直接注入EntityManagerFactory,
 * 另一种是通过 LocalContainerEntityManagerFactoryBean来间接注入.
 * 虽说这两种方法都是基于 LocalContainerEntityManagerFactoryBean的,但是在配置上还是有一些区别.
 **/
//@Configuration
//@EnableJpaRepositories(value = "com.marvin.springBoot.repository",
//        entityManagerFactoryRef = "readEntityManagerFactory",
//        transactionManagerRef = "readTransactionManager")
public class ReadDataSourceConfig {

    //@Autowired
    //JpaProperties jpaProperties;
    //
    //@Autowired
    //@Qualifier("readDruidDataSource")
    //private DataSource readDruidDataSource;
    //
    ///**
    // * 我们通过LocalContainerEntityManagerFactoryBean来获取EntityManagerFactory实例
    // *
    // * @return
    // */
    //@Bean(name = "readEntityManagerFactoryBean")
    //public LocalContainerEntityManagerFactoryBean readEntityManagerFactoryBean(EntityManagerFactoryBuilder builder) {
    //    return builder.dataSource(readDruidDataSource).properties(jpaProperties.getProperties()).packages("com.marvin.springBoot.persistence") //设置实体类所在位置
    //            .persistenceUnit("readPersistenceUnit").build();
    //    //.getObject();//不要在这里直接获取EntityManagerFactory
    //}
    //
    ///**
    // * EntityManagerFactory类似于Hibernate的SessionFactory,mybatis的SqlSessionFactory
    // * 总之,在执行操作之前,我们总要获取一个EntityManager,这就类似于Hibernate的Session,
    // * mybatis的sqlSession.
    // *
    // * @param builder
    // * @return
    // */
    //@Bean(name = "readEntityManagerFactory")
    //public EntityManagerFactory readEntityManagerFactory(EntityManagerFactoryBuilder builder) {
    //    return this.readEntityManagerFactoryBean(builder).getObject();
    //}
    //
    ///**
    // * 配置事物管理器
    // *
    // * @return
    // */
    //@Bean(name = "readTransactionManager")
    //public PlatformTransactionManager readTransactionManager(EntityManagerFactoryBuilder builder) {
    //    return new JpaTransactionManager(readEntityManagerFactory(builder));
    //}
}